﻿using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace template_dll
{
    public partial class Form10 : Form
    {
        public Form10()
        {
            InitializeComponent();
        }

        public SqlConnection conn;
        private DataTable dt = new DataTable();
        public int actionId = 0;

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > -1 && e.RowIndex > -1)
                if (MessageBox.Show("Удалить товар из группы?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SqlStorProc.sp_params[] par = new SqlStorProc.sp_params[2];
                    par[0].name = "@actionid";
                    par[0].value = actionId;
                    par[1].name = "@drugcode";
                    par[1].value = dataGridView1[0,e.RowIndex].Value;
                    new SqlStorProc().SqlProcExecNonQuery(conn, "pas_Actions_DrugGroupDel", 30, par);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (dt.Rows[i][0].ToString() == dataGridView1[0, e.RowIndex].Value.ToString())
                        {
                            dt.Rows.RemoveAt(i);
                            dataGridView1.Refresh();
                            break;
                        }
                    }
                }
        }

        private void Form10_Load(object sender, EventArgs e)
        {
            SqlStorProc.sp_params[] par1 = new SqlStorProc.sp_params[1];
            par1[0].name = "@actionid";
            par1[0].value = actionId;
            dt = new SqlStorProc().SqlProcExecWithQueryOneTable(conn, "pas_Actions_DrugGroupSel", 300, par1);
            dataGridView1.DataSource = dt.DefaultView;
        }
    }
}
